import base62 from 'base62-yf';
const qs = require('querystringify');

/**
 * 解析Url上的参数
 */
export const decodeURIParams = () => {
  const index = window.location.href.indexOf('?');
  if (index > -1) {
    const searchQueryStr = window.location.href.substring(index + 1);
    const { _openx_header, ...rest } = qs.parse(searchQueryStr);
    let headerParams = {};
    if (_openx_header) {
      const headerString = base62.decode(_openx_header) || '';
      headerParams = JSON.parse(headerString);
    }
    return {
      ...rest,
      ...headerParams,
    };
  } else {
    return {};
  }
};
